<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class Autocomplete extends MX_Controller {

	public function __construct() {
		parent::__construct();
		$this->load->model('category_model');

		$this->template->set_partial('top_nav', 'header/top_nav');
		$this->template->set_partial('footer', 'footer/footer');

		$this->template->set_partial('main_search', 'header/main_search');
		$this->template->set_partial('site_statistics', 'header/site_statistics');

	}
	
	
	function lawyer_search(){
			
		$search = $_GET['term'];
	
		$query = $this->db->query("SELECT id,title FROM `profile` WHERE `title` LIKE '%$search%' and status=51 ORDER BY title ASC limit 15") or die('Something went wrong');
		$result = $query->result();
	
		/*
		 $json = '[';
		$first = true;
		foreach($query->result() as $row):
	
		if (!$first) {
		$json .=  ',';
		} else { $first = false;
		}
	
		$json .= '{"value":"'.$row->id.'","label":"'.htmlentities(stripslashes($row->name)).'"}';
	
		endforeach;
		$json .= ']';
		//echo $json;
	
		*/
	
		$row_set = array();
	
		foreach ($result as $row1){
			$row = array(
					'label'	=> stripslashes($row1->title),
					'value'	=> 	(int)$row1->id
			);
			$row_set[] = $row;//build an array
		}
	
		echo json_encode($row_set);//format the array into json data
	
	
	
	}
	function find_location(){
			
		$search = $_GET['term'];
		$query = $this->db->query("SELECT id,cityname,statecode FROM `city` WHERE `cityname` LIKE '%$search%' ORDER BY cityname DESC limit 500") or die('Something went wrong');
		$result = $query->result();
		$row_set = array();
	
		foreach ($result as $row1){
			$row = array(
					'label'	=> stripslashes($row1->cityname).', '.$row1->statecode,
					'value'	=> 	(int)$row1->id
			);
			$row_set[] = $row;//build an array
		}
	
		echo json_encode($row_set);//format the array into json data
	
	}
	/*
	function business_search(){
			
		$search = $_GET['term'];
	
		$query = $this->db->query("SELECT title FROM `business_master` WHERE `title` LIKE '%$search%' ORDER BY title ASC limit 15") or die('Something went wrong');
		$json = '[';
		$first = true;
		foreach($query->result() as $row):
	
		if (!$first) {
			$json .=  ',';
		} else { $first = false;
		}
		$json .= '{"value":"'.$row->title.'"}';
	
		endforeach;
		$json .= ']';
		echo $json;
	}
	*/
	function find_phone_number(){
			
		$search = $_GET['term'];
	
		$query = $this->db->query("SELECT phone FROM `business_master` WHERE `phone` LIKE '%$search%' ORDER BY phone ASC limit 15") or die('Something went wrong');
		$json = '[';
		$first = true;
		foreach($query->result() as $row):
	
		if (!$first) {
			$json .=  ',';
		} else { $first = false;
		}
		$json .= '{"value":"'.$row->phone.'"}';
	
		endforeach;
		$json .= ']';
		echo $json;
	}
	
	
	
}

